<?php
class Report extends Controller {

	function Report() {
		parent::Controller();
        $this->load->model('Report_model', 'm');
		$this->load->model('Datum_model');
	}
	
	function index() {
    	redirect("/welcome", "refresh");
	}
	
	function daftar_jabatan_struktural($print_mode=false, $gol='') {
		if (!$this->session->userdata('username')) {
			$data['isLogin'] = FALSE;
        	redirect("/login", "location");
		} else {
			$data['isLogin'] = TRUE;
			$data['username'] = $this->session->userdata('username');
			$data['role'] = $this->session->userdata('role');
		}
		
		if ($print_mode) {
			$arr_golongan = $this->_buildKriteriaDaftarUrutEselon($gol);
			$tabel_header = $this->m->header_daftar_pejabat_struktural(true);
			$content      = $this->m->isi_daftar_pejabat_struktural(true, $arr_golongan);
			$data['list_data'] = $tabel_header.$content;
			$data['judul'] = 'DAFTAR PEJABAT STRUKTURAL ESELON '.$gol.br().'TAHUN '.date('Y');
			$this->load->view('view_print_report', $data);
		} else {
			if ( ($this->input->post('golongan'))||($gol != '') ) {
				if ($this->input->post('golongan')) {
					$golongan = $this->input->post('golongan');
				} else {
					$golongan = $gol;
				}
				$arr_golongan = $this->_buildKriteriaDaftarUrutEselon($golongan);
				$tabel_header = $this->m->header_daftar_pejabat_struktural();
		        $nama_variabel = 'data';
		        $isi = 'var '.$nama_variabel.'='.$this->m->isi_daftar_pejabat_struktural($print_mode, $arr_golongan);
				$data['additional_js'] = $this->_setJsPaging($isi, $nama_variabel, $tabel_header);
		        
				$data['judul'] = 'DAFTAR PEJABAT STRUKTURAL ESELON '.$golongan.' TAHUN '.date('Y');
				$data['panel'] = $this->_setPanelDaftarPejabatEselon($golongan);
				$data['link_cetak'] = base_url().'index.php/report/daftar_jabatan_struktural/true/'.$golongan;
				$data['tampilkan_menu'] = true;
				$this->load->view('view_report', $data);
			} else {
				$data['judul'] = 'DAFTAR PEJABAT STRUKTURAL ESELON';
				$data['panel'] = $this->_setPanelDaftarPejabatEselon();
				$this->load->view('view_report', $data);
			}
		}
	}

    function _comboGolongan($name, $selected="", $pilih='pilih', $class_style='', $extra='')  {
    	$pendidikan = array('I', 'II', 'III', 'IV');
        $CI =& get_instance();
        
        $retval = "<select ".($class_style=="" ? "" : "class=$class_style")." name=$name id=$name $extra>";
        if ($pilih=='pilih') {
        	$retval .= "<option value=\"\">-- pilih --</option>";
        } 
        //Get data 
        foreach ($pendidikan as $pend) {
            $retval .= "<option value=\"".$pend."\"";
            if ($pend==$selected) $retval .= " selected=\"selected\" ";
            $retval .= " >".$pend."</option>";
        }
        $retval .= "</select>";
        return $retval;
    }
    
	function _setPanelDaftarPejabatEselon($golongan="") {
    	$ret =  form_open('report/daftar_jabatan_struktural/').
				"<fieldset >
				 <table class=\"formTabel\" border=\"0\" align=\"center\" cellpadding=\"5\" cellspacing=\"1\">
				  <tr>
				    <td class=\"kolom\" valign=\"top\">Golongan : ".$this->_comboGolongan('golongan', $golongan)."
				    <td valign=\"top\"><input class=\"tombol\" type=\"submit\" name=\"button\" id=\"button\" value=\"Tampilkan\" /></td>
				 </tr>
				 </table>
				 </fieldset>".
				 form_close();
		return $ret;    	
    }
	
	function _setPanelDaftarUrutKepangkatan($instansi="") {
    	$ret =  form_open('report/daftar_urut_kepangkatan/').
				"<fieldset >
				 <table class=\"formTabel\" border=\"0\" align=\"center\" cellpadding=\"5\" cellspacing=\"1\">
				  <tr>
				    <td class=\"kolom\" valign=\"top\">Intansi : ".combo_instansi('instansi',$instansi)."
				    <td valign=\"top\"><input class=\"tombol\" type=\"submit\" name=\"button\" id=\"button\" value=\"Tampilkan\" /></td>
				 </tr>
				 </table>
				 </fieldset>".
				 form_close();
		return $ret;    	
    }
    
    function _setJsPaging($isi, $nama_variabel, $tabel_header) {
    	$ret = '
        <script type="text/javascript">
            '.$isi.'

            // This file demonstrates the different options of the pagination plugin
            // It also demonstrates how to use a JavaScript data structure to
            // generate the paginated content and how to display more than one
            // item per page with items_per_page.

            /**
             * Callback function that displays the content.
             *
             * Gets called every time the user clicks on a pagination link.
             *
             * @param {int}page_index New Page index
             * @param {jQuery} jq the container with the pagination links as a jQuery object
             */
			function pageselectCallback(page_index, jq){
                // Get number of elements per pagionation page from form
                var items_per_page = 15;
                var max_elem = Math.min((page_index+1) * items_per_page, '.$nama_variabel.'.length);
                var newcontent = \''.$tabel_header.'\';

                // Iterate through a selection of the content and build an HTML string
                for(var i=page_index*items_per_page;i<max_elem;i++)
                {
                    newcontent += '.$nama_variabel.'[i];
                }

                newcontent += \'</tbody></table>\';

                // Replace old content with new content
                $("#isi_tabel").html(newcontent);

                // Prevent click eventpropagation
                return false;
            }

            // When document has loaded, initialize pagination and form
            $(document).ready(function(){
                $("#paginasi").pagination('.$nama_variabel.'.length, {
                    items_per_page:'.ROW_PER_PAGE.',
                    num_edge_entries: '.NUM_EDGE_ENTRIES.',
                    next_text: \''.TEKS_NEXT.'\',
                    prev_text: \''.TEKS_PREV.'\',
                    next_show_always: '.ALWAYS_SHOW_NEXT.',
                    prev_show_always: '.ALWAYS_SHOW_PREV.',
                    callback:pageselectCallback
                });
            });
        </script>
    	';
    	return $ret;
    }
    
    function _buildKriteriaDaftarUrutEselon($gol) {
    	switch ($gol) {
    		case 'I': return(array(1,2));
    		case 'II': return(array(3,4));
    	    case 'III': return(array(5,6));
    	    case 'IV': return(array(7,8));
    	}
    }
    
	function _buildKriteriaDaftarUrutKepangkatan($gol) {
    	switch ($gol) {
    		case 'I': return(array(2,3,4));
    		case 'II': return(array(5,6,7,8));
    	    case 'III': return(array(9,10,11,12));
    	    case 'IV': return(array(13,14,15,16,17));
    	}
    }
    
	
	function daftar_urut_kepangkatan($print_mode=false, $instansi=0) {
		
		if (!$this->session->userdata('username')) {
			$data['isLogin'] = FALSE;
        	redirect("/login", "location");
		} else {
			$data['isLogin'] = TRUE;
			$data['username'] = $this->session->userdata('username');
			$data['role'] = $this->session->userdata('role');
		}
		
		if($this->input->post('instansi'))              
            $instansi = $this->input->post('instansi');    
        
		$nama_intansi = strtoupper( Datum_model::getData('nama','instansi','idspg_instansi = '.$instansi) );
		
		if ($print_mode) {			
			$tabel_header = $this->m->header_daftar_urut_kepangkatan(true);
			$content      = $this->m->isi_daftar_urut_kepangkatan(true, $instansi);
			
			$data['list_data'] = $tabel_header.$content;
			$data['judul'] = 'DAFTAR URUT KEPANGKATAN PEGAWAI NEGERI SIPIL <br/>'.$nama_intansi.br().strtoupper(NAMA_KABKOT).br().'PER '.strtoupper(getBulan(date('m'))).' TAHUN '.date('Y');
			$this->load->view('view_print_report', $data);
		} else {
			if ( ($this->input->post('instansi'))||($instansi != 0) ) {
								
				$tabel_header = $this->m->header_daftar_urut_kepangkatan();
		        $nama_variabel = 'data';
		        $isi = 'var '.$nama_variabel.'='.$this->m->isi_daftar_urut_kepangkatan($print_mode, $instansi);
				$data['additional_js'] = $this->_setJsPaging($isi, $nama_variabel, $tabel_header);
		        
				$data['judul'] = 'DAFTAR URUT KEPANGKATAN PEGAWAI NEGERI SIPIL  '.$nama_intansi.' TAHUN '.date('Y');
				$data['panel'] = $this->_setPanelDaftarUrutKepangkatan($instansi);
				$data['link_cetak'] = base_url().'index.php/report/daftar_urut_kepangkatan/true/'.$instansi;
				$data['tampilkan_menu'] = true;
				$this->load->view('view_report', $data);
			} else {
				$data['judul'] = 'DAFTAR URUT KEPANGKATAN PEGAWAI NEGERI SIPIL';
				$data['panel'] = $this->_setPanelDaftarUrutKepangkatan();
				$this->load->view('view_report', $data);
			}
		}
	}

	function jumlah_jabatan_struktural($print_mode=false) {
		if (!$this->session->userdata('username')) {
			$data['isLogin'] = FALSE;
        	redirect("/login", "location");
		} else {
			$data['isLogin'] = TRUE;
			$data['username'] = $this->session->userdata('username');
			$data['role'] = $this->session->userdata('role');
		}
		
		if ($print_mode) {
			$tabel_header = $this->m->header_jumlah_jabatan_struktural(true);
			$content      = $this->m->isi_jumlah_jabatan_struktural(true);
			$data['list_data'] = $tabel_header.$content;
			$data['judul'] = 'REKAPITULASI JUMLAH JABATAN STRUKTURAL'.br().'BULAN '.strtoupper( getBulan(date('n')) ).' '.date('Y');
			$this->load->view('view_print_report', $data);
		} else {
			$tabel_header = $this->m->header_jumlah_jabatan_struktural();
	        $nama_variabel = 'data';
	        $isi = 'var '.$nama_variabel.'='.$this->m->isi_jumlah_jabatan_struktural($print_mode);
			$data['additional_js'] = $this->_setJsPaging($isi, $nama_variabel, $tabel_header);
	        
			$data['judul'] = 'REKAPITULASI JUMLAH JABATAN STRUKTURAL'.br().'BULAN '.strtoupper( getBulan(date('n')) ).' '.date('Y');
			$data['link_cetak'] = base_url().'index.php/report/jumlah_jabatan_struktural/true/';
			$data['tampilkan_menu'] = true;
			$this->load->view('view_report', $data);
		}
	}

	
	function persentase_jabatan($print_mode=false) {
		if (!$this->session->userdata('username')) {
			$data['isLogin'] = FALSE;
        	redirect("/login", "location");
		} else {
			$data['isLogin'] = TRUE;
			$data['username'] = $this->session->userdata('username');
			$data['role'] = $this->session->userdata('role');
		}
		
		if ($print_mode) {
			$tabel_header = $this->m->header_persentase_jabatan(true);
			$content      = $this->m->isi_persentase_jabatan(true);
			$data['list_data'] = $tabel_header.$content;
			$data['judul'] = 'PERSENTASE  JUMLAH JABATAN STRKTURAL DAN NON STRUKTURAL'.br().'BULAN '.strtoupper( getBulan(date('n')) ).' '.date('Y');
			$this->load->view('view_print_report', $data);
		} else {
			$tabel_header = $this->m->header_persentase_jabatan();
	        $nama_variabel = 'data';
	        $isi = 'var '.$nama_variabel.'='.$this->m->isi_persentase_jabatan($print_mode);
			$data['additional_js'] = $this->_setJsPaging($isi, $nama_variabel, $tabel_header);
	        
			$data['judul'] = 'PERSENTASE  JUMLAH JABATAN STRKTURAL DAN NON STRUKTURAL'.br().'BULAN '.strtoupper( getBulan(date('n')) ).' '.date('Y');
			$data['link_cetak'] = base_url().'index.php/report/persentase_jabatan/true/';
			$data['tampilkan_menu'] = true;
			$this->load->view('view_report', $data);
		}
	}
	
	
	function jabatan_struktural($print_mode=false) {
		if (!$this->session->userdata('username')) {
			$data['isLogin'] = FALSE;
        	redirect("/login", "location");
		} else {
			$data['isLogin'] = TRUE;
			$data['username'] = $this->session->userdata('username');
			$data['role'] = $this->session->userdata('role');
		}
		
		$data['judul'] = 'DAFTAR JABATAN STRUKTURAL'.br().'BULAN '.strtoupper( getBulan(date('n')) ).' '.date('Y');
		if ($print_mode) {
			$tabel_header = $this->m->header_jabatan_struktural(true);
			$content      = $this->m->isi_jabatan_struktural(true);
			$data['list_data'] = $tabel_header.$content;
			$this->load->view('view_print_report', $data);
		} else {
			$tabel_header = $this->m->header_jabatan_struktural();
	        $nama_variabel = 'data';
	        $isi = 'var '.$nama_variabel.'='.$this->m->isi_jabatan_struktural($print_mode);
			$data['additional_js'] = $this->_setJsPaging($isi, $nama_variabel, $tabel_header);
	        
			$data['link_cetak'] = base_url().'index.php/report/jabatan_struktural/true/';
			$data['tampilkan_menu'] = true;
			$this->load->view('view_report', $data);
		}
	}
	
	
}
?>